home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 January / macformat46.iso / Shareware Plus / Developers / ASTcl 1.0 / ASTcl-1.0 / ASTclMacAppInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  5.2 KB  |  214 lines

  1. /*
  2.  * ASTcl -- DoAppleScript package for MacTcl 7.5.1
  3.  * This code adds the command "DoAppleScript <script>" to MacTcl.
  4.  *
  5.  * ASTclMacAppInit.c -- 
  6.  *    Provides a version of the Tcl_AppInit procedure for the example shell.
  7.  * Written on 960927.
  8.  * 
  9.  * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
  10.  * Copyright (c) 1995-1996 Sun Microsystems, Inc.
  11.  *
  12.  * See the file "license.terms" for information on usage and redistribution
  13.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14.  *
  15.  * modified by Theodore C. Belding
  16.  * University of Michigan Program for the Study of Complex Systems
  17.  * <mailto:Ted.Belding@umich.edu>
  18.  * <http://www-personal.engin.umich.edu>
  19.  * 
  20.  */
  21.  
  22. #include "tcl.h"
  23. #include "tclInt.h"
  24. #include "tclPort.h"
  25.  
  26. #include "ASTcl.h"
  27.  
  28. #include <Events.h>
  29.  
  30. #if defined(THINK_C)
  31. #   include <console.h>
  32. #elif defined(__MWERKS__)
  33. #   include <SIOUX.h>
  34. short InstallConsole _ANSI_ARGS_((short fd));
  35. #endif
  36.  
  37. #ifdef TCL_TEST
  38. EXTERN int        Tcltest_Init _ANSI_ARGS_((Tcl_Interp *interp));
  39. #endif /* TCL_TEST */
  40.  
  41. typedef int (*TclMacConvertEventPtr) _ANSI_ARGS_((EventRecord *eventPtr));
  42. void     TclMacSetEventProc _ANSI_ARGS_((TclMacConvertEventPtr procPtr));
  43.  
  44. /*
  45.  * Forward declarations for procedures defined later in this file:
  46.  */
  47.  
  48. static int        MacintoshInit _ANSI_ARGS_((void));
  49.  
  50. /*
  51.  *----------------------------------------------------------------------
  52.  *
  53.  * main --
  54.  *
  55.  *    Main program for tclsh.  This file can be used as a prototype
  56.  *    for other applications using the Tcl library.
  57.  *
  58.  * Results:
  59.  *    None. This procedure never returns (it exits the process when
  60.  *    it's done.
  61.  *
  62.  * Side effects:
  63.  *    This procedure initializes the Macintosh world and then 
  64.  *    calls Tcl_Main.  Tcl_Main will never return except to exit.
  65.  *
  66.  *----------------------------------------------------------------------
  67.  */
  68.  
  69. void
  70. main(argc, argv)
  71.     int argc;                /* Number of arguments. */
  72.     char **argv;            /* Array of argument strings. */
  73. {
  74.     char *newArgv[2];
  75.     
  76.     if (MacintoshInit()  != TCL_OK) {
  77.     Tcl_Exit(1);
  78.     }
  79.  
  80.     argc = 1;
  81.     newArgv[0] = "tclsh";
  82.     newArgv[1] = NULL;
  83.     Tcl_Main(argc, newArgv, Tcl_AppInit);
  84. }
  85.  
  86. /*
  87.  *----------------------------------------------------------------------
  88.  *
  89.  * Tcl_AppInit --
  90.  *
  91.  *    This procedure performs application-specific initialization.
  92.  *    Most applications, especially those that incorporate additional
  93.  *    packages, will have their own version of this procedure.
  94.  *
  95.  * Results:
  96.  *    Returns a standard Tcl completion code, and leaves an error
  97.  *    message in interp->result if an error occurs.
  98.  *
  99.  * Side effects:
  100.  *    Depends on the startup script.
  101.  *
  102.  *----------------------------------------------------------------------
  103.  */
  104.  
  105. int
  106. Tcl_AppInit(interp)
  107.     Tcl_Interp *interp;        /* Interpreter for application. */
  108. {
  109.     if (Tcl_Init(interp) == TCL_ERROR) {
  110.     return TCL_ERROR;
  111.     }
  112.  
  113. #ifdef TCL_TEST
  114.     if (Tcltest_Init(interp) == TCL_ERROR) {
  115.     return TCL_ERROR;
  116.     }
  117. #endif /* TCL_TEST */
  118.  
  119.     /*
  120.      * Call the init procedures for included packages.  Each call should
  121.      * look like this:
  122.      *
  123.      * if (Mod_Init(interp) == TCL_ERROR) {
  124.      *     return TCL_ERROR;
  125.      * }
  126.      *
  127.      * where "Mod" is the name of the module.
  128.      */
  129.  
  130.     /*
  131.      * Initialize ASTcl extension
  132.      *
  133.      */
  134.      
  135.     if (ASTcl_Init(interp)==TCL_ERROR) {
  136.         return TCL_ERROR;
  137.     }
  138.  
  139.     /*
  140.      * Call Tcl_CreateCommand for application-specific commands, if
  141.      * they weren't already created by the init procedures called above.
  142.      */
  143.  
  144.     /*
  145.      * Specify a user-specific startup file to invoke if the application
  146.      * is run interactively.  On the Mac we can specifiy that this file
  147.      * is in the application's resource fork.  A traditional file location
  148.      * may also be used.
  149.      */
  150.  
  151.     Tcl_Eval(interp, "source -rsrc {tclshrc}");
  152.     Tcl_ResetResult(interp);
  153.  
  154.     /* Tcl_SetVar(interp, "tcl_rcFileName", "~/.tclshrc", TCL_GLOBAL_ONLY); */
  155.     return TCL_OK;
  156. }
  157.  
  158. /*
  159.  *----------------------------------------------------------------------
  160.  *
  161.  * MacintoshInit --
  162.  *
  163.  *    This procedure calls initalization routines to set up a simple
  164.  *    console on a Macintosh.  This is necessary as the Mac doesn't
  165.  *    have a stdout & stderr by default.
  166.  *
  167.  * Results:
  168.  *    Returns TCL_OK if everything went fine.  If it didn't the 
  169.  *    application should probably fail.
  170.  *
  171.  * Side effects:
  172.  *    Inits the appropiate console package.
  173.  *
  174.  *----------------------------------------------------------------------
  175.  */
  176.  
  177. static int
  178. MacintoshInit()
  179. {
  180. #if defined(THINK_C)
  181.  
  182.     /* Set options for Think C console package */
  183.     /* The console package calls the Mac init calls */
  184.     console_options.pause_atexit = 0;
  185.     console_options.title = "\pTcl Interpreter";
  186.         
  187. #elif defined(__MWERKS__)
  188.  
  189.     /* Set options for CodeWarrior SIOUX package */
  190.     SIOUXSettings.autocloseonquit = true;
  191.     SIOUXSettings.showstatusline = true;
  192.     SIOUXSettings.asktosaveonclose = false;
  193.     InstallConsole(0);
  194.     SIOUXSetTitle("\pTcl Interpreter");
  195.         
  196. #elif defined(applec)
  197.  
  198.     /* Init packages used by MPW SIOW package */
  199.     InitGraf((Ptr)&qd.thePort);
  200.     InitFonts();
  201.     InitWindows();
  202.     InitMenus();
  203.     TEInit();
  204.     InitDialogs(nil);
  205.     InitCursor();
  206.         
  207. #endif
  208.  
  209.     TclMacSetEventProc((TclMacConvertEventPtr) SIOUXHandleOneEvent);
  210.     
  211.     /* No problems with initialization */
  212.     return TCL_OK;
  213. }
  214.